<template>
  <el-popover placement="right-start" :width="250" trigger="hover" :show-after="100" :hide-after="300"
    @before-enter="userDetailsBeforeEnter()">
    <template #reference>
      <div class="index-user-root">
        <img v-if="userinfo.avatar != ''" class="index-user-avatar" :src="userinfo.avatar" />
        <img v-else class="index-user-avatar" src="@/assets/imgs/default_user_avatar.jpg">
        <div class="index-user-introduction">
          <div class="index-nickname">{{ userinfo.nickname }}</div>
          <div class="index-username">{{ userinfo.username }}</div>
        </div>
      </div>
    </template>
    <indexUserDetails></indexUserDetails>
  </el-popover>
</template>

<script setup lang="ts">
import indexUserDetails from "./IndexUserDetails.vue";
import { storeToRefs } from 'pinia';
import { useAuthStore } from '@/stores/auth';
import { onMounted } from "vue";

const authStore = useAuthStore();
const { userinfo } = storeToRefs(authStore);

onMounted(() => {
})

const userDetailsBeforeEnter = () => {
}
</script>

<style scoped lang="scss">
.index-user-root {
  @include flex(row, space-between, flex-start);
  @include box(100%, 75px);
  padding: 10px 10px 10px 10px;
  cursor: pointer;
  transition: background-color 0.3s;

  &:hover {
    background-color: var(--el-color-primary-light-9);
  }

  .index-user-avatar {
    @include box(55px, 55px);
    border-radius: 10px;
  }

  .index-user-introduction {
    @include flex(column, space-around, flex-end);
    @include box(calc(100% - 55px), 100%);
    text-align: right;
    color: var(--el-color-primary);
    letter-spacing: 0;
    padding-left: 10px;

    div {
      width: 100%;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .index-nickname,
    .index-username {
      text-shadow: 2px 2px 5px rgba(0, 0, 0, .2);

      [class="dark"] & {
        text-shadow: 2px 2px 5px rgba(0, 0, 0, 1);
      }
    }

    .index-nickname {
      @include font(18px, 700);
    }

    .index-username {
      @include font(13px);
      margin-top: 3px;
    }
  }
}

.user-detail-popover {
  background-color: var(--el-color-primary-light-5);
}
</style>